package com.example.practice03.controller;

import com.example.practice03.bean.RegionStats;
import com.example.practice03.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private DataService dataService;

    //获取所有的数据
    @RequestMapping("/")
    public  String index(Model model){
        List<RegionStats> list = dataService.getAllList();
        System.out.println(list);
        model.addAttribute("list",list);
        return "index";
    }
    //搜索地区
    @RequestMapping("/state")
    public String state(@ModelAttribute("state") String state,Model model){
        List<RegionStats> list = new ArrayList<>();
        list = dataService.getListByState(state);
        model.addAttribute("list",list);
        return "index";
    }
    //搜索国家
    @RequestMapping("/country")
    public String country(@ModelAttribute("country") String country,Model model){
        List<RegionStats> list = new ArrayList<>();
        list = dataService.getListByCountry(country);
        model.addAttribute("list",list);
        return "index";
    }
}
